/*
Copyright (c) 2011, Nimar S. Arora
All rights reserved.
*/

#include <stdio.h>
#include <stdlib.h>

#include "network.h"
#include "ergo.h"

int main(int argc, char ** argv)
{
  /* comand line arguments */
  char * p_model_fname;
  char * p_evidence_fname;
  int seed;
  int numsamples;
  int lag;
  int anneal;
  
  Graph_t * p_model;
  Instance_t * p_inst;

  printf("%s -- Gibbs Sampling for Bayes Nets\n", PACKAGE_STRING);

  if (argc != 7)
  {
    fprintf(stderr, "Error: Usage gsbn <network-file> <evidence-file>"
            " <seed> <number-of-samples> <lag> <anneal?>\n");
    return 1;
  }

  p_model_fname = argv[1];
  p_evidence_fname = argv[2];
  seed = atoi(argv[3]);
  numsamples = atoi(argv[4]);
  lag = atoi(argv[5]);
  anneal = atoi(argv[6]);
  
  /* print the arguments */
  printf("Network: %s, Evidence %s\n", p_model_fname, p_evidence_fname);
  printf("Seed = %d, Samples = %d with Lag = %d %s\n", seed, numsamples,
         lag, anneal ? "and injected annealing" : "");

  /* set the seed for the random number generator */
  srand(seed);

  /* parse the Bayes Net */
  p_model = ergo_parse_network(p_model_fname);
  
  /* parse the Evidence */
  p_inst = ergo_parse_evidence(p_evidence_fname, p_model);

  /* now generate the MCMC samples */
  mcmc(p_model, p_inst, numsamples, lag, anneal);
  
  return 0;
}

